<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.wxtf.platform.plugins.user.*"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	UserBean user = (UserBean)request.getSession().getAttribute("userBean");
	String _db = user.getDbType();
	String level = user.getOrgLevel(user.getCurOrgId());
	
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <base href="<%=basePath%>"/>
    
    <title>个人设置</title>
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<meta http-equiv="pragma" content="no-cache"/>
	<meta http-equiv="cache-control" content="no-cache"/>
	<meta http-equiv="expires" content="0"/>    
	
	<link type="text/css" rel="stylesheet" href="ligerUI/skins/Aqua/css/ligerui-all.css" />
	<link type="text/css" rel="stylesheet" href="ligerUI/skins/<%=user.getUserCss()%>/css/ligerui-all.css" />
	<link type="text/css" rel="stylesheet" href="ligerUI/skins/ligerui-icons.css" />
	<link type="text/css" rel="stylesheet" href="resource/css/style.css" />


	<script type="text/javascript" src="js/jquery/jquery-1.7.2.js"></script>
	<script type="text/javascript" src="ligerUI/js/core/base.js"></script>
	<script type="text/javascript" src="ligerUI/js/ligerui.min.js"></script>
	<script type="text/javascript" src="js/common.js"></script>
	<script type="text/javascript" src="js/validata.js"></script>
	
	<script type="text/javascript" src="ligerUI/js/plugins/ligerDialog.js"></script>
    <script type="text/javascript" src="ligerUI/js/plugins/ligerGrid.js"></script>
	<script type="text/javascript" src="ligerUI/js/plugins/ligerTree.js"></script>
	<script type="text/javascript" src="ligerUI/js/plugins/ligerDateEditor.js"></script>
	
	<script type="text/javascript">
		var _db = '<%=_db%>';
			
		_jsonObj.classname = "com.wxtf.platform.plugins.user.UserAction";
		_jsonObj.methodname = "getUserByUserId";
		_jsonObj.logicdata = '[{"userId":"<%=user.getUserId()%>"}]';
		$(function(){
			reload();
		});
		function reload(){
			callserver(_jsonObj, function(data, satus){
				$("#user_id").val(data.user_id);
				$("#userlay_user_id").val(data.user_id);
				$("#t_user_id").val(data.user_id);				
				$("#user_passwd").val(data.user_passwd);
				$("#caption").val(data.caption);
				$("#action").val(data.action);
				$("#useraction").val(data.action);
				$("#user_email").val(data.user_email);				
				$("#user_office_tel").val(data.user_office_tel);
				$("#user_tel").val(data.user_tel);
				$("#user_mobilephone").val(data.user_mobilephone);
				$("#user_fax").val(data.user_fax);
				$("#user_address").val(data.user_address);
				$("#user_sex").val(data.user_sex);
				$("#user_birthday").ligerDateEditor({format: "yyyy-MM-dd", width: 180, initValue: ''+data.user_birthday+'' });								
				$("#userlay").val(data.user_eduation);

				var val = data.user_position_id;
				if(val != ''){
					var objs = document.getElementsByName('user_position_id');
					switch(parseInt(val)){
						case 1: objs[0].checked = true; break;
						case 2: objs[1].checked = true; break;
						case 3: objs[0].checked = true; objs[1].checked = true; break;
						case 4: objs[2].checked = true; break;
						case 5: objs[0].checked = true; objs[2].checked = true; break;
						case 6: objs[1].checked = true; objs[2].checked = true; break;
						case 7: objs[0].checked = true; objs[1].checked = true; objs[2].checked = true; break;
						case 8: objs[3].checked = true; break;
						case 9: objs[0].checked = true; objs[3].checked = true; break;
						case 10: objs[1].checked = true; objs[3].checked = true; break;
						case 11: objs[0].checked = true; objs[1].checked = true; objs[3].checked = true; break;
						case 12: objs[2].checked = true; objs[3].checked = true; break;
						case 13: objs[0].checked = true; objs[2].checked = true; objs[3].checked = true; break;
						case 14: objs[1].checked = true; objs[2].checked = true; objs[3].checked = true; break;
						case 15: objs[0].checked = true; objs[1].checked = true; objs[2].checked = true; objs[3].checked = true; break;
					}
				}
			},function(data, satus){
				warningTip(data.resultrecord);
			});
		}
		//检查email邮箱
		function isEmail(str){
			if(str == ''){
				return true;
			}
       		var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
       		return reg.test(str);
		}
		//修改用户信息
		function userupdate(){
			var param = { 
				"classname": "com.wxtf.platform.plugins.user.UserAction",
				"methodname": "modifyUser",
				"logicdata": "[]",
				"extenddata": "[]"
			};
			var user_id = $("#user_id").val();
			var caption = $("#caption").val();
			var action = $("#action").val();
			var user_email = $("#user_email").val();				
			var user_office_tel = $("#user_office_tel").val();
			var user_tel = $("#user_tel").val();
			var user_mobilephone = $("#user_mobilephone").val();
			var user_fax = $("#user_fax").val();
			var user_address = $("#user_address").val();
			var user_birthday = $("#user_birthday").val();
			if(fucCheckLength(caption.trim()) <= 0 || fucCheckLength(caption.trim()) > 50){
				warningTip("显示名称：不能为空且不能超过50字符");
				return;
			}
			if(fucCheckLength(action.trim()) <= 0 || fucCheckLength(action.trim()) > 150){
				warningTip("登录名称：不能为空且不能超过150字符");
				return;
			}
			if(fucCheckLength(user_fax.trim()) > 50){
				warningTip("用户传真：不能超过50字符");
				return;
			}
			if(fucCheckLength(user_office_tel.trim()) > 50){
				warningTip("办公电话：不能超过50字符");
				return;
			}
			if(!checkIsNum(user_office_tel.trim())){
				warningTip("办公电话：必须为整数");
				return;
			}
			if(fucCheckLength(user_tel.trim()) > 50){
				warningTip("家庭电话：不能超过50字符");
				return;
			}
			if(!checkIsNum(user_tel.trim())){
				warningTip("家庭电话：必须为整数");
				return;
			}
			if(fucCheckLength(user_email.trim()) > 50){
				warningTip("用户邮箱：不能超过50字符");
				return;
			}
			if(!isEmail(user_email.trim())){
				warningTip("用户邮箱：格式不正确");
				return;
			}
			if(fucCheckLength(user_mobilephone.trim()) > 50){
				warningTip("移动电话：不能超过50字符");
				return;
			}
			if(!checkIsMobile(user_mobilephone.trim())){
				warningTip("移动电话：格式不正确");
				return;
			}
			if(!checkIsNum(user_mobilephone.trim())){
				warningTip("移动电话：必须为数字");
				return;
			}
			if(fucCheckLength(user_address.trim()) > 50){
				warningTip("家庭住址：不能超过50字符");
				return;
			}
			
			param.logicdata = getForm("user_updateform");
			callserver(param,function(data, satus){
				succMsgTip(data.resultrecord);
				reload();
			},function(data, satus){
				warningTip(data.resultrecord);
			});		
		}
		//修改用户密码
		function updatemima(){
			var param = { 
				"classname": "com.wxtf.platform.plugins.user.UserAction",
				"methodname": "modifyPwd",
				"logicdata": "[]",
				"extenddata": "[]"
			};
			var userPwd = $("#userPwd").val();
			var userPass = $("#userPass").val();
			var userPassword = $("#userPassword").val();
			if(fucCheckLength(userPwd.trim()) <= 0 || fucCheckLength(userPwd.trim()) > 50){
				warningTip("密码：不能为空且不能超过50字符");
				return;
			}
			if(fucCheckLength(userPass.trim()) <= 0 || fucCheckLength(userPass.trim()) > 50){
				warningTip("新密码：不能为空且不能超过50字符");
				return;
			}
			if(fucCheckLength(userPassword.trim()) <= 0 || fucCheckLength(userPassword.trim()) > 50){
				warningTip("确认密码：不能为空且不能超过50字符");
				return;
			}
			if(userPass.trim()!=userPassword.trim()){
				warningTip("新密码和确认密码不一样");
				return;
			}
			param.logicdata = getForm("user_Password_updateform");
			callserver(param,function(data, satus){;
				succMsgTip(data.resultrecord);
				$("#userPwd").val("");
				$("#userPass").val("");
				$("#userPassword").val("");
				reload();
			},function(data, satus){
				warningTip(data.resultrecord);
			});
		}
		//修改布局
		function userlayupdate(){
			var param = { 
				"classname": "com.wxtf.platform.plugins.user.UserAction",
				"methodname": "modifyUserlay",
				"logicdata": "[]",
				"extenddata": "[]"
			};
			var userlay_user_id = $("#userlay_user_id").val();
			var userlay = $("#userlay").val();
			param.logicdata = '[{"user_id":"'+userlay_user_id+'","userlay":"'+userlay+'"}]';
			callserver(param,function(data, satus){
				succMsgTip(data.resultrecord);
				top.location.href="<%=basePath%>jsp/sys/"+userlay;
			},function(data, satus){
				warningTip(data.resultrecord);
			});
		}

		//修改显示机构级别
		function updViewOrg(){
			var level = '<%=level%>';
			if(parseInt(level) > 1){
				warningTip('只有一级、二级部门才能操作此项');
				return;
			}
			
			var vals = 0;
			var objs = document.getElementsByName('user_position_id');
			for(var i=0; i<objs.length; i++){
				var obj = objs[i];
				if(obj.checked){
					vals += parseInt(obj.value);
				}
			}
			var param = { 
				"classname": "com.wxtf.platform.plugins.user.UserAction",
				"methodname": "updViewOrg",
				"logicdata": '[{"user_position_id":"' + vals + '"}]',
				"extenddata": "[]"
			};
			callserver(param,function(data, satus){
				succMsgTip(data.resultrecord);
			},function(data, satus){
				warningTip(data.resultrecord);
			});
		}
		
	</script>
  </head>
  
  <body>
  		<h3>修改用户信息</h3>
   		<form id="user_updateform">
   		<input type="hidden" id="user_id" name="user_id" value=""/>
   		<input type="hidden" id="useraction" name="useraction" value="" />
   			<table class="form_table">   			
   				<tr>
   					<td class="form_label">显示名称：</td><td><input class="textbg1" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'" type="text" id="caption" name="caption"/></td>
   					<td class="form_label">登录名称：</td><td><input class="textbg1" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'" type="text" id="action" name="action"/></td>
   					<td>&nbsp;&nbsp;</td>
   					<td rowspan="5"><input class="btn1" name="xinxisubmit" onclick="userupdate();" type="button" value="提交"/></td>
   				</tr>
   				<tr>
   					<td class="form_label">用户性别：</td><td><select id="user_sex" name="user_sex" style="width:180px;">
   						<option value="N">男</option>
   						<option value="Y">女</option>
   					</select></td>
   					<td class="form_label">出生日期：</td><td>
   					<input readonly="readonly" type="text" id="user_birthday" name="user_birthday" style="width:180px;"/></td>
   				</tr>
   				<tr>
   					<td class="form_label">用户传真：</td><td><input class="textbg1" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'" type="text" id="user_fax" name="user_fax"/></td>
   					<td class="form_label">办公电话：</td><td><input class="textbg1" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'" type="text" id="user_office_tel" name="user_office_tel"/></td>
   				</tr>
   				<tr>
   					<td class="form_label">家庭电话：</td><td><input class="textbg1" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'" type="text" id="user_tel" name="user_tel"/></td>
   					<td class="form_label">用户邮箱：</td><td><input class="textbg1" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'" type="text" id="user_email" name="user_email"/></td>
   				</tr>
   				<tr>
   					<td class="form_label">移动电话：</td><td><input class="textbg1" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'" type="text" id="user_mobilephone" name="user_mobilephone"/></td>
   					<td class="form_label">家庭住址：</td><td><input class="textbg1" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'" type="text" id="user_address" name="user_address"/></td>
   				</tr>
   			</table>
   		</form>
   		
  		<hr/>
   		<h3>修改布局</h3>
   		<form id="user_userlay_updateform">
   		<input type="hidden" id="userlay_user_id" name="userlay_user_id" value=""/>
   			<table class="form_table">
   				<tr>
   					<td class="form_label">布局方式：</td>
   					<td>
   						<select id="userlay" name="userlay" style="width:170px;">
   							<option value="index.jsp" selected="selected">树状菜单布局</option>
   							<option value="index1.jsp">下拉菜单布局</option>
   						</select>
   					</td>
   					<td>&nbsp;&nbsp;</td>
   					<td><input class="btn1" name="userlaysubmit" onclick="userlayupdate();" type="button" value="提交"/></td>
   				</tr>
   			</table>
   		</form>
   		
  		<hr/>
   		<h3>修改用户名/密码</h3>
   		<form id="user_Password_updateform">
   		<input type="hidden" id="t_user_id" name="t_user_id" value=""/>
   		<input type="hidden" id="user_passwd" name="user_passwd" value="" />
   			<table class="form_table">
   				<tr>
   					<td class="form_label">密码：</td><td><input class="textbg1" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'" type="password" id="userPwd" name="userPwd"/></td>
   					<td>&nbsp;&nbsp;</td>
   					<td rowspan="3"><input class="btn1" name="mimasubmit" onclick="updatemima();" type="button" value="提交"/></td>
   				</tr>
   				<tr>
   					<td class="form_label">新密码：</td><td><input class="textbg1" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'" type="password" id="userPass" name="userPass"/></td>
   				</tr>
   				<tr>
   					<td class="form_label">确认密码：</td><td><input class="textbg1" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'" type="password" id="userPassword" name="userPassword"/></td>
   				</tr>
   			</table>
   		</form>
   		
  		<hr/>
   		<h3>登录页面显示部门级别</h3>
		<table class="form_table">
			<tr>
				<td class="form_label">部门级别：</td>
				<td><input name="user_position_id" type="checkbox" value="1" />一级部门&nbsp;&nbsp;</td>
				<td><input name="user_position_id" type="checkbox" value="2" />二级部门&nbsp;&nbsp;</td>
				<td><input name="user_position_id" type="checkbox" value="4" />三级部门&nbsp;&nbsp;</td>
				<td><input name="user_position_id" type="checkbox" value="8" />四级部门</td>
				<td>&nbsp;&nbsp;</td>
				<td><input class="btn1" onclick="updViewOrg();" type="button" value="提交"/></td>
			</tr>
		</table>
  </body>
</html>
